﻿#ifndef CANTHREAD_H
#define CANTHREAD_H

#include <QThread>
#include "ControlCAN.h"
#include <QDebug>
#include <QTimer>
#include <atomic>



#include <QObject>

class CANThread : public QObject
{
    Q_OBJECT
public:
    explicit CANThread(QObject *parent = nullptr);
    ~CANThread();


    UINT m_deviceType;
    UINT m_debicIndex;
    UINT m_baundRate;
    UINT m_debicCom;

private:
    std::atomic<bool> stopped{false};
    QTimer *timer;


signals:
    void resultReady(const QString &result); // 发送处理结果的信号
    void finished(); // 任务完成的信号
    void getProtocolData(VCI_CAN_OBJ *vci,unsigned int dwRel,unsigned int channel);
    void boardInfo(VCI_BOARD_INFO vbi);

    void deviceOpened(bool state);

    void deviceClosed(bool state);

    void deviceInited();

    void deviceReseted();

    void deviceStarted();

    void senddataend();


public slots:
    void checkCANData();


    void start();

    void stop();
    //1.打开设备
    bool openDevice(UINT deviceType,UINT debicIndex,UINT baundRate);

    //2.初始化CAN
    bool initCAN();

    //3.启动CAN
    bool startCAN();

    //4.发送数据
    bool sendData(UINT channel,UINT ID,BYTE remoteFlag,BYTE externFlag,const unsigned char *data,BYTE len);



    //5.关闭设备
    void closeDevice();

    //0.复位设备，  复位后回到3
    bool reSetCAN();
};


#endif // CANTHREAD_H
